//
//  My_ReleaseChange.m
//  HappyStore
//
//  Created by 李小辉 on 16/6/22.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "My_ReleaseChange.h"
#import "MyReleaseChangeInfo.h"
#import "ReleaseImageCell.h"
@interface My_ReleaseChange ()
@property (strong, nonatomic) NSArray *aryItem;
@property (strong, nonatomic) NSArray *imageAry;//装图片
@end

@implementation My_ReleaseChange



- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];

}



- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];


}
- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"我的发布";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //初始化
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 3 ) {//政府
        self.aryItem = @[@"项目",@"资金",@"活动"];
    }else{
        self.aryItem = @[@"项目",@"资金",@"活动",@"服务",@"招聘"];//企业、个人
    }
    //图片
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 3) {
        self.imageAry = @[@"发布-我的项目",@"发布-我的资金",@"发布-我的活动"];
    }else{
        self.imageAry = @[@"发布-我的项目",@"发布-我的资金",@"发布-我的活动",@"发布-我的服务",@"发布-我的招聘"];
    }
    
    //不可滚动
    self.tableView.scrollEnabled = NO;
    //去掉多余的表格线
    [self setExtraCellLineHidden:self.tableView];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setExtraCellLineHidden:(UITableView *)tableView{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.aryItem.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ReleaseImageCell *cell = [[ReleaseImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Rcell"];
    cell.textLabel.textColor = RGB(89, 87, 87);
    cell.textLabel.text = self.aryItem[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.imageView.image = [UIImage imageNamed:self.imageAry[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    MyReleaseChangeInfo *releaseVC = [[MyReleaseChangeInfo alloc] init];
    
    releaseVC.titleStr = self.aryItem[indexPath.row];
    
    [self.navigationController pushViewController:releaseVC animated:YES];
    
}






//解决表格线不到左边界
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}


- (void)viewDidLayoutSubviews{
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}

@end
